package com.java.util;

import com.java.Enum.AreaAccess;
import com.java.Enum.PriceAccess;
import java.io.Serializable;


/**
 * @Author: ZhangJin
 * @Date: 2020/9/10 22:59
 */
public class ErrorRangeUtil  implements Serializable {


    /* Depth error range  +- 1m */

    public static Boolean isNotLocateRangeForDepth(String needDepth,String dataDepth){

        if (needDepth == null || needDepth.equals(""))
            /* 如果前端传入的深度为空,则不作为筛选条件,直接返回true */
         return true;
        String s = PatternUtil.deleteString(dataDepth);
        if (!s.equals("mistake data")) {
            Double dataDepth1 = Double.parseDouble(s);
            Double needDepth1 = Double.parseDouble(PatternUtil.deleteString(needDepth));
            /* [needDepth1-2,needDepth1+2] */
            if (dataDepth1 >= (needDepth1 - 2) && dataDepth1 <= (needDepth1 + 2)) {
                return true;
            }
        }
         return false;
    }

    /* Width error range  +- 1m */
    public static Boolean isNotLocateRangeForWidth(String needWidth,String dataWidth){

        if (needWidth == null|| needWidth.equals(""))
            /* 如果前端传入的宽度为空,则不作为筛选条件,直接返回true */
            return true;
        String s = PatternUtil.deleteString(dataWidth);
        if (!s.equals("mistake data")) {
            Double dataWidth1 = Double.parseDouble(s);
            Double needWidth1 = Double.parseDouble(PatternUtil.deleteString(needWidth));
            /* [needDepth1-2,needDepth1+2] */
            if (dataWidth1 >= (needWidth1 - 2) && dataWidth1 <= (needWidth1 + 2)) {
                return true;
            }
        }
        return false;
    }

    /* Area error range   */

    public static Boolean isNotLocateRangeForArea(String needArea,String dataArea){

        if (needArea == null || needArea.equals(""))
            /* 如果前端传入的Area为空,则不作为筛选条件,直接返回true */
            return true;
        String s = PatternUtil.deleteString(dataArea);
        if (!s.equals("mistake data")) {
            Double dataArea1 = Double.parseDouble(s);
            Double needArea1 = Double.parseDouble(PatternUtil.deleteString(needArea));
            if (AreaAccess.getTypeBtArea(dataArea1) == AreaAccess.getTypeBtArea(needArea1))
                return true;
        }
        return false;
    }


    /* Price error range   */

    public static Boolean isNotLocateRangeForPrice(String needPrice,String dataPrice){
        if (needPrice == null || needPrice.equals(""))
            /* 如果前端传入的Area为空,则不作为筛选条件,直接返回true */
            return true;
        String s = PatternUtil.deleteString(dataPrice);
        if (!s.equals("mistake data")) {
            Double dataPrice1 = Double.parseDouble(s);
            Double needPrice1 = Double.parseDouble(PatternUtil.deleteString(needPrice));
            if (PriceAccess.getTypeBtPrice(dataPrice1) == PriceAccess.getTypeBtPrice(needPrice1) || PriceAccess.getTypeBtPrice(dataPrice1).getType().equals("面议")) {
                return true;
            }
        }
        return false;
    }


    /* silu  去除字符串  剩下的就是数字  */
    public static void main(String[] args) {
        System.out.println(isNotLocateRangeForPrice("10000元", "30000元"));
    }




}
